//
//  ContentView.swift
//  swifttest1
//
//  Created by kologe on 2024/9/5.
//

import SwiftUI

struct ContentView: View {
    @State var name: String = ""
    @State var password: String = ""
    @ObservedObject var dataDic = kzListener.conDic
    @State var dealData:Bool = false
    @State private var selectedTab = 1 // 使用 @State 变量来跟踪当前选择的标签页
    
    @State var cc:Int = 0
    
    @State var uploadWd:WindowDelegate =  WindowDelegate()
    
    @ObservedObject var pauseArr = fileListenPauseArr
    
    var body: some View {
        ZStack{
            VStack {
                TabView(selection: $selectedTab,
                        content:  {
                    ScanList().tabItem { 
                        Text("scan")
                    }.tag(1)
                    
                    DownloadListView(dataArr:fileDownloadArr,status: .constant(1) ).tabItem { Text("download")
                    }.tag(2)
                    
                    SpeedView().tabItem{
                        Text("speed")
                    }.tag(3)
                })
                HStack{
                    Spacer()
                    Button(action:{
                        print("RedDot")
                        //弹出新的window显示发送的数据的情况
                        if uploadWd.popupWindow?.isVisible == true {
                            uploadWd.closeWindow()
                        }else{
                            cc = fileUploadArr.array.count
                            uploadWd.setTitle(title: "发送情况")
                            uploadWd.setSize(size: NSMakeSize(500, 400))
                            let view = DownloadListView(dataArr: fileUploadArr,status: .constant(0))
                            uploadWd.openWindow(view: view)
                        }
                    }){
                        RedDotView(count: $cc,arr: fileUploadArr)
                    }
                }
                
            }
            .padding()
            .sheet(isPresented: $dataDic.state){
                ReceiveDataListView(dataDic: kzListener.conDic)
            }
//            .onReceive(pauseArr.$state) { state in
//                if state{
//                    let vv = FileResumeListView()
//                    WindowDelegate.openWindow(view: vv, title: "resume", size:NSMakeSize(300, 150) )
//                }
//            }

            
        }
    }
    
}

#Preview {
    ContentView()
}
